package com.young.springboot.kafka;

import com.googlecode.aviator.AviatorEvaluator;

import java.util.HashMap;
import java.util.Map;

/**
 * @description：
 * @author: yangyahui01
 * @date: 11/29/24 12:49 PM
 */
public class AviatorELMatcher implements Matcher<Map<String, Object>> {
    private final String expression;

    public AviatorELMatcher(String expression) {
        this.expression = expression;
    }

    public boolean match(Map<String, Object> env) {
        return matches(this.expression, env);
    }

    public static boolean matches(String expression, Map<String, Object> env) {
        return expression != null && env != null ? (Boolean) AviatorEvaluator.execute(expression, env, false) : false;
    }

    public static boolean matches(String expression, Map<String, Object> env, boolean cached) {
        return expression != null && env != null ? (Boolean)AviatorEvaluator.execute(expression, env, cached) : false;
    }

    public static void main(String[] args) {
        Map<String, Object> env = new HashMap();
        env.put("meteor", "2.1.4");
        System.out.println(matches("meteor <= '2.1.5'", env));
    }

    public static class Test {
        private String name;
        private int age;

        public Test() {
        }

        public String getName() {
            return this.name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return this.age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}